package com.changgou;

import entity.IdWorker;
import org.springframework.amqp.core.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import tk.mybatis.spring.annotation.MapperScan;

/**
 * @Author: wzw
 * @Date: 2020/12/6 21:23
 * @version: 1.8
 */
@SpringBootApplication //启动类
@EnableEurekaClient //开启客户端
@MapperScan(basePackages = {"com.changgou.goods.dao"}) //包扫描
public class GoodsApplication {
    public static void main(String[] args) {
        SpringApplication.run(GoodsApplication.class, args);
    }

    //注入IdWoker
    @Bean
    public IdWorker idWorker(){
        return new IdWorker(1, 1);
    }

    //创建search队列
    @Bean
    public Queue searchQueue(){
        return new Queue("search-queue", true);
    }
    //创建item队列
    @Bean
    public Queue itemQueue(){
        return new Queue("item-queue", true);
    }
    //创建交换机
    @Bean
    public Exchange goodsExchange(){
        return new DirectExchange("goods-exchange", true, false);
    }

    //交换机及与该两个队列绑定
    @Bean
    public Binding bindQueueToExchangeBySearch(Exchange goodsExchange, Queue searchQueue) {
        return BindingBuilder.bind(searchQueue).to(goodsExchange).with("goods-routing-key").noargs();
    }
    @Bean
    public Binding bindQueueToExchangeByItem(Exchange goodsExchange,Queue itemQueue) {
        return BindingBuilder.bind(itemQueue).to(goodsExchange).with("goods-routing-key").noargs();
    }
}

